Completed
Push — master ( 27b20f...cb95fb )
by greg
49s
created

post-upload.js ➔ ... ➔ req.busboy.file   C

Complexity

Conditions 12
Paths 3

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 12
c 1
b 0
f 0
nc 3
dl 0
loc 40
rs 5.1612
nop 5

How to fix   Complexity   

Complexity

Complex classes like post-upload.js ➔ ... ➔ req.busboy.file often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
import {
2
  abeExtend,
3
  cmsMedia
4
} from '../../cli'
5
6
var route = function(req, res, next){
7
  abeExtend.hooks.instance.trigger('beforeRoute', req, res, next)
8
  if(typeof res._header !== 'undefined' && res._header !== null) return
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9
10
  var image = cmsMedia.image.saveFile(req)
11
12
  image.then(function (resp) {
13
    res.set('Content-Type', 'application/json')
14
    res.send(JSON.stringify(resp))
15
  }).catch(function(e) {
16
    console.error('[ERROR] post-upload', e)
17
  })
18
}
19
20
export default route
21